<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{ width: 100px; height: 100px; background-color: skyblue;position: absolute; top:0;left: 0;}
    </style>
</head>
<body>
    <div></div>
    <script src="common.js"></script>
    <script>
        document.querySelector('div').onclick = function(){
            let timer = setInterval(()=>{
                // 获取当前的left值  this现在表示的是当前div的dom对象 箭头函数自己没有找上层
                let left = parseInt(getStyle(this,'left'))
                console.log(left);
                // 判断是否已经运动到结束位置
                if(left == 300){
                    clearInterval(timer);
                }else{
                    this.style.left = left + 5 +'px'
                }
            },20)
        }
    </script>
</body>
</html>